package com.pengshun.modules.api.transport.controller;

import com.pengshun.config.NoRepeatSubmit;
import com.pengshun.modules.api.coal.validator.First;
import com.pengshun.modules.api.coal.validator.Second;
import com.pengshun.modules.api.transport.dto.TransportDto;
import com.pengshun.modules.api.transport.dto.TransportTakeOrderDto;
import com.pengshun.modules.api.transport.service.UserTransportService;
import com.pengshun.modules.common.BaseResult;
import com.pengshun.modules.domain.User;
import com.pengshun.modules.security.Authorization;
import com.pengshun.modules.security.CurrUserInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequiredArgsConstructor
@Api(tags = "用户货运管理")
@RequestMapping("/api/usertransport")
public class UserTransportController {

    private final UserTransportService userTransportService;

    @ApiOperation(value = "用户货运信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "sort", value = "排序", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "infoType", value = "信息类型", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "freightTypeCode", value = "货运类型", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "freightTransportCode", value = "货物类型", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "vehicleTypeId", value = "车辆类型", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "vehicleLengthId", value = "车辆长度", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "merchantId", value = "商户id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "longitude", value = "经度", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "latitude", value = "纬度", dataType = "double", paramType = "query"),
            @ApiImplicitParam(name = "showPosition", value = "显示位置（0 默认，1：系统首页，2：货运首页抢单，3：货运首页列表，4：货运抢单，）", dataType = "double", paramType = "query"),
    })
    @GetMapping(value = "/user-list")
    public BaseResult userList(@ApiIgnore @Validated(value = {Second.class}) TransportDto para) throws Exception {
        BaseResult res = userTransportService.userList(para);
        return res;
    }

    @ApiOperation(value = "货运顶部信息")
    @GetMapping(value = "/top-info")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "size", value = "条数", dataType = "int", required = true, paramType = "query"),
    })
    public BaseResult topInfo(@ApiIgnore @Validated(value = {Second.class}) TransportDto para) throws Exception {
        BaseResult res = userTransportService.topInfo(para);
        return res;
    }

    @ApiOperation(value = "货运信息详情")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "货运id", dataType = "int", required = true, paramType = "query"),
    })
    @GetMapping(value = "/detil")
    public BaseResult detil(  @ApiIgnore @Validated(value = {First.class}) TransportDto para) throws Exception {
        BaseResult res = userTransportService.detil(para);
        return res;
    }
    @ApiOperation(value = "承运")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "transportId", value = "货运id", dataType = "int", required = true, paramType = "query"),
            @ApiImplicitParam(name = "orderId", value = "订单id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "carOwnerId", value = "接单车辆Id", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "carOwnerNum", value = "接单车牌号", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gatheringUserId", value = "收款人id", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gatheringUserName", value = "收款人姓名", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "gatheringUserPhone", value = "收款人电话", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "carTypeName", value = "车辆类型名称", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "number", value = "接取数量", dataType = "double", required = true,paramType = "query"),
            @ApiImplicitParam(name = "userName", value = "接单人姓名", dataType = "string", required = true,paramType = "query"),
            @ApiImplicitParam(name = "freight", value = "运费", dataType = "double", required = true,paramType = "query"),
            @ApiImplicitParam(name = "infoFee", value = "信息费", dataType = "double", required = true,paramType = "query"),
            @ApiImplicitParam(name = "loadFee", value = "装车费", dataType = "double", required = true,paramType = "query"),
            @ApiImplicitParam(name = "unloadFee", value = "卸车费", dataType = "double", required = true,paramType = "query"),
            @ApiImplicitParam(name = "poundsFee", value = "磅费", dataType = "double", required = true,paramType = "query"),
            @ApiImplicitParam(name = "otherFee", value = "其他费用", dataType = "double", required = true,paramType = "query"),
            @ApiImplicitParam(name = "totalFreight", value = "总运费", dataType = "double", required = true, paramType = "query"),
            @ApiImplicitParam(name = "transportDate", value = "接单日期yyyy-MM-dd", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "transportStartTime", value = "开始时间HH:mm", dataType = "string", required = true, paramType = "query"),
            @ApiImplicitParam(name = "transportEndTime", value = "结束时间HH:mm", dataType = "string", required = true, paramType = "query"),
    })
    @PostMapping(value = "/take")
    @Authorization
    @NoRepeatSubmit
    public BaseResult take(@ApiIgnore @CurrUserInfo User user, @ApiIgnore @Validated(value = {First.class}) TransportTakeOrderDto para) throws Exception {
        para.setUserId(user.getId());
        para.setPhone(user.getPhone());
        BaseResult res = userTransportService.takeOrder(para);
        return res;
    }
}
